package com.aya;

import com.aya.mapper.model.*;
import com.aya.property.definition.CustomProperty;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringAnalysis {


    @Test
    public void testAgent() {
        CustomProperty childBean = new CustomProperty();
        childBean.setId("3");
        String id = childBean.getId();
        System.out.println(id);
    }

    @Test
    public void testGetBean() {
        String [] paths = {"applicationContext.xml"};
        ApplicationContext factory = new ClassPathXmlApplicationContext(paths,true,null);
        ChildBean bean = factory.getBean("childBean",ChildBean.class);
        bean.send();
        System.out.println(bean.getName());
    }

    @Test
    public void testValueBean() {
        ApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        ValueBean bean = factory.getBean("valueBean", ValueBean.class);
        System.out.println(bean);

    }

    @Test
    public void testApplicationContextGetBean() {
        ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");

        factory.close();
    }

    @Test
    public void testApplicationContextRegistry() {
        ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        SimpleInjectBean registryMap = factory.getBean("registryMapTest", SimpleInjectBean.class);
        System.out.println(registryMap);

        System.out.println( factory.getBean("frozenMap"));
        factory.close();
    }

    Logger logger= Logger.getLogger(getClass());
    @Test
    public void testInjectProperty() {
        ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");

        logger.info( factory.getBean(User.class));
        factory.close();
    }

    @Test
    public void testInjectNestedProperty() {
        ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");

        logger.info( factory.getBean(NestedProperty.class));
        factory.close();
    }

    @Test
    public void testMultiApp() {
        ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext-dup.xml");

        logger.info( factory.getBean(ChildBean.class));
        factory.close();
    }
}
